import 'package:flutter/material.dart';
import 'package:flutter_learn_route/page/NewsPage.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[

        RaisedButton(
          child: Text('第二种传参方式，通过arguments传参, 利用命名路由和传到构造函数中'),
          onPressed: () {
            Navigator.pushNamed(context, '/news2', arguments: {
              'title': '第二种传参方式',
              'content': '命名路由+参数是比较常见的传参方式, pageContentBuilder可以动态调用构造函数'
            });
          },
          color: Theme.of(context).accentColor,
          textTheme: ButtonTextTheme.primary,
        ),
    RaisedButton(
    child: Text('第一种传参方式，通过push + RouteSetting(arguments:{xxx})传参'),
    onPressed: () {
            Navigator.push(context,
              MaterialPageRoute(
                builder: (context)=> NewsPage(),
                settings: RouteSettings(
                  arguments: {
                    'title':'张三',
                    'content': '第一种跳转方式，通过push + RouteSetting传参,可以通过调用 ModalRoute.of(context).settings.arguments来获取'
                  }
                )
              )
            );
          },
          color: Theme.of(context).accentColor,
          textTheme: ButtonTextTheme.primary,
        ),
        RaisedButton(
          child: Text('不传参跳转'),
          onPressed: () {
            Navigator.pushNamed(context, '/news');
          },
          color: Theme.of(context).accentColor,
          textTheme: ButtonTextTheme.primary,
        ),
      ],
    );
  }
}
